package net.cloudcodex.client.main.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.inject.Inject;

/**
 * 
 * 
 * @author ADaroussin
 */
public class RegisterViewImpl extends DecoratedPopupPanel implements RegisterView {

	private final TextBox nicknameTextBox;
	private final Button validateButton;
	private final Button cancelButton;
	

	@Inject
	public RegisterViewImpl(Constant constant, Message message) {
		super(false, true);

		this.setGlassEnabled(true);

		final VerticalPanel panel = new VerticalPanel();
		this.add(panel);

		final Label registerLabel = new Label(message.getLabelRegister());
		registerLabel.setStyleName(constant.getLabelRegisterStyle());
		panel.add(registerLabel);

		final HorizontalPanel nicknamePanel = new HorizontalPanel();
		final Label nicknameLabel = new Label(message.getLabelNickname());
		nicknamePanel.add(nicknameLabel);
		nicknameTextBox = new TextBox();
		nicknamePanel.add(nicknameTextBox);
		panel.add(nicknamePanel);

		validateButton = new Button(message.getButtonValidate());
		cancelButton = new Button(message.getCancelButton());
		FlowPanel buttonPanel = new FlowPanel();
		
		buttonPanel.add(validateButton);
		buttonPanel.add(cancelButton);
		
		panel.add(buttonPanel);
		
	}

	@Override
	public void showPopup() {
		this.center();
	}

	@Override
	public void hidePopup() {
		this.hide();
	}

	@Override
	public HasClickHandlers getValidateButton() {
		return validateButton;
	}

	@Override
	public HasClickHandlers getCancelButton() {
		return cancelButton;
	}
	
	@Override
	public String getNickName() {
		return nicknameTextBox.getValue();
	}

}
